#ifndef _LOCK_HPP_
#define _LOCK_HPP_

#include "noncopyable.hpp"
#include "base.hpp"

namespace mina
{
	namespace thread
	{
		class Lock : public NonCopyable
		{
			public :
				friend class Condition;
			public :
				Lock();
				~Lock();

				void lock();
				void unlock();
				bool lock(long ms);
				bool try_lock();

			private :
				pthread_mutex_t _mutex;

				DECL_LOGGER(logger);
		};

		class AutoLock 
		{
			public :
				AutoLock(Lock & lock) : _lock(lock) 
			{
				_lock.lock();
			}

				~AutoLock()
				{
					_lock.unlock();
				}
			public :
				Lock & _lock;

			private :
				AutoLock & operator = (const AutoLock &);
		};
	}
}

#endif

